/**
 * 
 */
package com.jinmei.service.impl;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.dao.DataAccessException;

import com.jinmei.dao.EmployeeDao;
import com.jinmei.dao.WorkScheduleDao;
import com.jinmei.model.Employee;
import com.jinmei.pushclient.PushClientProxy;
import com.jinmei.service.EmployeeService;
import com.jinmei.utils.JinmeiConsts;

/**
 * @author richard
 *
 */
public class EmployeeServiceImpl implements EmployeeService {
	
	private EmployeeDao employeeDao;
	private WorkScheduleDao workScheduleDao;
	
	public EmployeeDao getEmployeeDao() {
		return employeeDao;
	}

	public void setEmployeeDao(EmployeeDao employeeDao) {
		this.employeeDao = employeeDao;
	}
	
	public WorkScheduleDao getWorkScheduleDao() {
		return workScheduleDao;
	}

	public void setWorkScheduleDao(WorkScheduleDao workScheduleDao) {
		this.workScheduleDao = workScheduleDao;
	}

	@Override
	public List<Employee> findAllEmployees() throws DataAccessException {
		return getEmployeeDao().findAllEmployees();
	}

	@Override
	public List<Employee> findEmployeeByfNumberAndName(String fNumber, String name)
			throws DataAccessException {
		return getEmployeeDao().findEmpolyeeByFNumberAndName(fNumber, name);
	}

	@Override
	public String sysncEmployee(String operFlg, Employee employee)
			throws DataAccessException {
		try{
			if(("1").equals(operFlg)){
				//new/modify
//				employee.setIsDeleted(0);
				getEmployeeDao().saveOrUpdateEmployee(employee);
			}
			if(("2").equals(operFlg)){
				//delete
				if (StringUtils.isEmpty(employee.getfNumber())) {
					return JinmeiConsts.FAILED;
				}
				
				getEmployeeDao().deleteEmployee(employee);
			}
			return JinmeiConsts.SUCCEED;
		}catch(DataAccessException e){
			e.printStackTrace();
			return JinmeiConsts.FAILED;
		}
	}

	@Override
	public Employee findEmployee(String fNumber) throws DataAccessException {
		return getEmployeeDao().findEmployee(fNumber);
	}
	
}
